<template>
    <div>
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="租赁人">
                    <el-input
                        class="w-[280px]"
                        v-model="queryParams.keys"
                        clearable
                        @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="工位状态">
                  <el-select class="w-[280px]" v-model="queryParams.status">
                    <el-option label="全部" :value="0" />
                    <el-option label="空闲" :value="1" />
                    <el-option label="租赁" :value="2" />
                    <el-option label="预定中" :value="3" />
                  </el-select>
                </el-form-item>
                <el-form-item label="场地">
                  <el-select class="w-[280px]" v-model="queryParams.office_place_id">
                    <el-option v-for="(item,index) in searchInfo.office_list" :key="index" :label="item.name" :value="item.id" />
                  </el-select>
                </el-form-item>
                <el-form-item label="场地区域">
                  <el-select class="w-[280px]" v-model="queryParams.district_id">
                    <el-option label="全部" value="" />
                    <el-option v-for="(item,index) in searchInfo.district_list" :key="index" :label="`${item.office_name}-${item.name}`" :value="item.id" />
                  </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>

        <el-card class="!border-none" shadow="never">
            <el-table size="large" v-loading="pager.loading" :data="pager.lists">
                <el-table-column label="工位名称" min-width="180" prop="name"/>
                <el-table-column label="工位状态" min-width="180" prop="statusinfo">
                    <template #default="{row}">
                        <span v-if="row.statusinfo.status == 0">空闲</span>
                        <span v-else-if="row.statusinfo.status == 1">租住中</span>
                        <span v-else-if="row.statusinfo.status == 2">过期</span>
                        <span v-else-if="row.statusinfo.status == 3">预定中</span>
                        <span v-else>空闲</span>
                    </template>
                </el-table-column>
                <el-table-column label="租赁人" min-width="180" >
                    <template #default="{row}">
                        <span v-if="row.user.username">{{ row.user.username }}</span>
                        <span v-else>-</span>
                    </template>
                </el-table-column>
                <el-table-column label="租赁结束时间" min-width="180" prop="statusinfo.end_time"/>
                <el-table-column label="季付金额" min-width="120" prop="price"/>
                <el-table-column label="半年付金额" min-width="120" prop="ban_nian_price"/>
                <el-table-column label="年付金额" min-width="120" prop="nian_price"/>
                <el-table-column label="押金" min-width="120" prop="server_price"/>
                <el-table-column label="订单编号" prop="statusinfo.sn" min-width="190">
					<template #default="{ row }">
						<el-link type="primary">
							<router-link :to="{ path: getRoutePath('seat.seatOrder/orderInfo'), query: { id: row.statusinfo.order_id } }" > {{ row.statusinfo.sn }} </router-link>
						</el-link>
					</template>
				</el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>
<script lang="ts" setup name="officePlaceSeat">
import { seatList, seatSeach } from '@/api/office/officePlace'
import { usePaging } from '@/hooks/usePaging'
import {getRoutePath} from '@/router'
const route = useRoute()
const queryParams:any = reactive({
    keys: '',
    status: 0,
    office_place_id: '',
    district_id: ''
})
const searchInfo:any = ref({
    district_list: [],
    office_list: []
})
const getSearch = async () => {
    const res = await seatSeach({});
    console.log(res)
    searchInfo.value = res;
}
const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: seatList,
    params: queryParams
})

getSearch()
if (route.query.id) {
    queryParams.office_place_id = Number(route.query.id);
    getLists()
} else {
    getLists()
}

</script>